package com.marvels.common.dto.pay;

import com.github.pagehelper.Page;
import com.marvels.common.dto.PageInfoDTO;

import java.io.Serializable;
import java.util.HashMap;

/**
* @ClassName: MarvelsResultDTO
* @Description:
* @author 李瑶
* @date 2018年1月17日 上午9:43:26
*
*/
public class MarvelsPayResultDTO implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private String code;
	private String message = "";
	private Object data;


	public static MarvelsPayResultDTO getResult(String code ,String message ,Object data){
		MarvelsPayResultDTO marvelsResult = new MarvelsPayResultDTO();
		marvelsResult.setCode(code);
		marvelsResult.setMessage(message);
		Object obj = null;
		if(data == null){
			obj = new HashMap<String, Object>();
		}else if(data instanceof Page<?>){
			Page<?> pageData = (Page<?>)data;
			obj = new PageInfoDTO(pageData);
		}else{
			obj = data;
		}
		marvelsResult.setData(obj);
		return marvelsResult;
	}

	public static MarvelsPayResultDTO getSuccessResult(Object data){
		MarvelsPayResultDTO marvelsResult = new MarvelsPayResultDTO();
		marvelsResult.setCode("0");
		marvelsResult.setMessage("成功");
		Object obj = null;
		if(data == null){
			obj = new HashMap<String, Object>();
		}else if(data instanceof Page<?>){
			Page<?> pageData = (Page<?>)data;
			obj = new PageInfoDTO(pageData);
		}else{
			obj = data;
		}
		marvelsResult.setData(obj);
//		MarvelsLogUtil.getInstance().info("obj:"+ JSONUtil.toJsonStr(obj));
		return marvelsResult;
	}
	public static MarvelsPayResultDTO getFailResult(String code ,String message){
		MarvelsPayResultDTO marvelsResult = new MarvelsPayResultDTO();
		marvelsResult.setCode(code);
		marvelsResult.setMessage(message);
		marvelsResult.setData(null);
		return marvelsResult;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@Override
	public String toString() {
		return "MarvelsResultDTO [code=" + code + ", message=" + message + ", data=" + data + "]";
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
